import { ModalController } from '@ionic/angular';
import { forEach } from '@angular/router/src/utils/collection';
import { EventService } from 'src/app/shared/service/event.service';
import { Component, Input, OnInit } from '@angular/core';

@Component({
  selector: 'app-invoice-head-list',
  templateUrl: './invoice-head-list.component.html',
  styleUrls: ['./invoice-head-list.component.scss'],
})
export class InvoiceHeadListComponent implements OnInit {
  @Input() tagData: any;
  constructor(
    private eventService: EventService,
    private modalCtrl: ModalController,

  ) { }

  ngOnInit() {}
  onClick(item) {
    this.eventService.eventEmit.emit('invoice-head-id', {id: item.id});
    item.check = "true";
    this.tagData.data.data.forEach(element => {
      if (element !== item) {
        element.check = "false";
      }
    });
    this.closeModal();
  }
  async closeModal() {
    try {
      const modal = this.modalCtrl.getTop();
      if (modal !== undefined) {
        (await modal).dismiss();
      }
    } catch (error) {
    }
  }
}
